/**
 * 网络组件
 */
#pragma once

#include "EventObject.h"
#include "ExecuteQueue.h"

#define MAX_EPOLL_EVENT 100

/* 服务器返回类型 */
typedef enum
{
	NETWORK_RET_TYPE_NONE	= 0,
	NETWORK_RET_TYPE_CLOSE	= 1,
	NETWORK_RET_TYPE_NORMAL = 2,
} NetworkRetType;

/* 网络能力对象 */
typedef struct _NetworkObject NetworkObject;
#define NETWORK_OBJECT(any) ((NetworkObject *)any)

extern NetworkObject *network_object_new(void);

/**
 * @brief 初始化网络对象
 */
extern void network_object_init(NetworkObject *self);

/**
 * @brief 将任务节点添加至网络对象，将自动启动发送方法。
 *        还需继续优化，目前无多路复用
 */
extern void network_object_add_task(NetworkObject *self, ExecuteQueue *q_node);

/**
 * @brief 连接 accept 信号处理函数到本 NetworkObject 对象
 */
extern void network_object_signal_connect_accept(
	NetworkObject *self,
	void (*accept_handler)(EventObject *handler, ExecuteQueue *q_node),
	EventObject *handler);

#define NETWORK_CALLBACK(any_function) \
	((void (*)(EventObject *, ExecuteQueue *))any_function)

/**
 * @brief 循环监听处理事件
 * @return 1. 正常，0: 退出
 */
extern int network_object_loop_wait(NetworkObject *self);
